define(["jquery", "bootstrap", "backend", "table", "form"], function (
  $,
  undefined,
  Backend,
  Table,
  Form
) {
  var Controller = {
    index: function () {
      // 初始化表格参数配置
      Table.api.init({
        extend: {
          index_url: "subject/chapter/index" + location.search,
          add_url: "subject/chapter/add",
          edit_url: "subject/chapter/edit",
          del_url: "subject/chapter/del",
          // multi_url: 'subject/chapter/multi',
          // import_url: 'subject/chapter/import',
          table: "subject_chapter",
        },
      });

      var table = $("#table");

      // 初始化表格
      table.bootstrapTable({
        url: $.fn.bootstrapTable.defaults.extend.index_url,
        pk: "id",
        sortName: "createtime",
        queryParams: function (query) {
          //表格默认追加搜索条件
          let filter = query.filter ? JSON.parse(query.filter) : {};                //过滤Url参数
          let ids = Fast.api.query("ids");
      
          filter.subid = ids;

          query.filter = JSON.stringify(filter);

          return query;
        },
        columns: [
          [
            { checkbox: true },
            { field: "id", title: __("Id") },
            { field: "subid", title: __("Subid") },
            {
              field: "title",
              title: __("Title"),
              operate: "LIKE",
              table: table,
              class: "autocontent",
              formatter: Table.api.formatter.content,
            },
            {
              field: "createtime",
              title: __("Createtime"),
              operate: "RANGE",
              addclass: "datetimerange",
              autocomplete: false,
              formatter: Table.api.formatter.datetime,
            },
            {
              field: "operate",
              title: __("Operate"),
              table: table,
              events: Table.api.events.operate,
              formatter: Table.api.formatter.operate,
            },
          ],
        ],
      });

      // 为表格绑定事件
      Table.api.bindevent(table);
    },
    add: function () {
      Controller.api.bindevent();
    },
    edit: function () {
      Controller.api.bindevent();
    },
    api: {
      bindevent: function () {
        Form.api.bindevent($("form[role=form]"));
      },
    },
  };
  return Controller;
});
